package com.qi.controller;

import cn.dev33.satoken.annotation.SaCheckLogin;
import cn.dev33.satoken.annotation.SaCheckRole;
import cn.dev33.satoken.annotation.SaIgnore;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.qi.common.RoleKey;
import com.qi.common.Status;
import com.qi.pojo.dto.AddClubBody;
import com.qi.pojo.dto.UpdateClubBody;
import com.qi.pojo.entity.Club;
import com.qi.pojo.vo.AjaxResult;
import com.qi.services.IClubService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/admin/club")
@Tag(name = "社团信息管理")
public class ClubController {

    @Resource
    private IClubService clubService;

    @SaCheckRole(RoleKey.超级管理员)
    @Operation(summary = "添加社团信息")
    @PostMapping("/insert")
    public AjaxResult add(@RequestBody AddClubBody addClubBody) {
        clubService.add(addClubBody);
        return AjaxResult.ok("社团信息添加成功");
    }

    @SaCheckRole(RoleKey.超级管理员)
    @Operation(summary = "删除社团信息")
    @GetMapping("/remove/{clubId}")
    public AjaxResult remove(@PathVariable("clubId") Long clubId) {
        clubService.delete(clubId);
        return AjaxResult.ok("社团信息删除成功");
    }

    @SaCheckRole(RoleKey.超级管理员)
    @Operation(summary = "修改社团信息")
    @PostMapping("/modify")
    public AjaxResult modify(@RequestBody UpdateClubBody updateClubBody) {
        clubService.modify(updateClubBody);
        return AjaxResult.ok("社团信息修改成功");
    }

    @SaCheckLogin
    @Operation(summary = "查询社团列表")
    @GetMapping("/listPage/{current}/{size}")
    public AjaxResult listPage(@PathVariable("current") Long current,
                               @PathVariable("size") Long size) {

        IPage<Club> clubPage = clubService.listPage(current, size);
        return AjaxResult.success(clubPage);
    }

    @SaCheckLogin
    @Operation(summary = "根据社团id查询社团信息")
    @GetMapping("/getById/{clubId}")
    public AjaxResult getById(@PathVariable("clubId") Long clubId) {
        Club club = clubService.getClubById(clubId);
        return AjaxResult.success(club);
    }
}
